//
//  MailTableViewCell.m
//  chongwu
//
//  Created by 隼目 on 2021/9/15.
//

#import "MailTableViewCell.h"

@implementation MailTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
-(void)creatTopView{
    self.backgroundColor=[UIColor clearColor];
    
    UIView *centerView=[UIView new];
    [self.contentView addSubview:centerView];
    [centerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(30*_mainWidth);
        make.right.mas_equalTo(-30*_mainWidth);
        make.top.mas_equalTo(10*_mainHeight);
        make.bottom.mas_equalTo(-10*_mainHeight);
    }];
    centerView.backgroundColor=[UIColor whiteColor];
    centerView.layer.cornerRadius=25*_mainWidth;
    
    UIView *xianView=[UIView new];
    [centerView addSubview:xianView];
    [xianView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(113*_mainWidth);
        make.right.mas_equalTo(-45*_mainWidth);
        make.height.mas_equalTo(1);
        make.centerY.mas_equalTo(0);
    }];
    xianView.backgroundColor=rgba(232,232,232,1);
    
    UIView *topView=[UIView new];
    [centerView addSubview:topView];
    [topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.mas_equalTo(0);
        make.bottom.mas_equalTo(xianView.mas_top);
    }];
    
    UILabel *mailLabel=[UILabel new];
    [topView addSubview:mailLabel];
    [mailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(30*_mainWidth);
        make.centerY.mas_equalTo(0);
        make.width.height.mas_equalTo(63*_mainWidth);
    }];
    mailLabel.textAlignment=NSTextAlignmentCenter;
    mailLabel.backgroundColor=rgba(34,40,54,1);
    mailLabel.layer.masksToBounds=YES;
    mailLabel.layer.cornerRadius=63*_mainWidth/2;
    mailLabel.text=@"寄";
    mailLabel.font=[UIFont fontWithName:@"FZHei-B01" size:autoScaleW(25)];
    mailLabel.textColor=rgba(255,255,255,1);
    
    UILabel *mailAddressLabel=[UILabel new];
    [topView addSubview:mailAddressLabel];
    [mailAddressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(xianView);
        make.right.mas_equalTo(-182*_mainWidth);
        make.bottom.mas_equalTo(mailLabel.mas_centerY).mas_equalTo(-_mainHeight*5);
    }];
    mailAddressLabel.numberOfLines=0;
    mailAddressLabel.font=[UIFont fontWithName:@"PingFang SC" size:autoScaleW(35)];
    mailAddressLabel.text=@"杭州市阳光母婴中心";
    mailAddressLabel.textColor=rgba(47,47,47,1);
    
    UILabel *mailNameLabel=[UILabel new];
    [topView addSubview:mailNameLabel];
    [mailNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(xianView);
        make.right.mas_equalTo(-182*_mainWidth);
        make.top.mas_equalTo(mailLabel.mas_centerY).mas_equalTo(_mainHeight*5);
    }];
    mailNameLabel.numberOfLines=0;
    mailNameLabel.font=[UIFont fontWithName:@"PingFang SC" size:autoScaleW(35)];
    mailNameLabel.text=@"金有才\t13605443326";
    mailNameLabel.textColor=rgba(102,102,102,1);
    
    UIButton *maileBtn=[UIButton new];
    [topView addSubview:maileBtn];
    [maileBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-40*_mainWidth);
        make.centerY.mas_equalTo(0);
        make.width.mas_equalTo(101*_mainWidth);
        make.height.mas_equalTo(38*_mainHeight);
    }];
    [maileBtn setTitle:@"地址簿" forState:0];
    [maileBtn  setTitleColor:rgba(157,157,157,1) forState:0];
    maileBtn.titleLabel.font=[UIFont fontWithName:@"PingFang SC" size:autoScaleW(26)];
    maileBtn.layer.masksToBounds=YES;
    maileBtn.layer.borderColor=rgba(157,157,157,1).CGColor;
    maileBtn.layer.borderWidth=1;
    maileBtn.layer.cornerRadius=38*_mainHeight/2;
    maileBtn.tag=1;
    [maileBtn addTarget:self action:@selector(selectPushToAddressBtn:) forControlEvents:UIControlEventTouchUpInside];
    
    UIView *bottomView=[UIView new];
    [centerView addSubview:bottomView];
    [bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(0);
        make.top.mas_equalTo(xianView.mas_bottom);
    }];
    
    UILabel *collectLabel=[UILabel new];
    [bottomView addSubview:collectLabel];
    [collectLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(30*_mainWidth);
        make.centerY.mas_equalTo(0);
        make.width.height.mas_equalTo(63*_mainWidth);
    }];
    collectLabel.textAlignment=NSTextAlignmentCenter;
    collectLabel.backgroundColor=rgba(255,102,0,1);
    collectLabel.layer.masksToBounds=YES;
    collectLabel.layer.cornerRadius=63*_mainWidth/2;
    collectLabel.text=@"收";
    collectLabel.font=[UIFont fontWithName:@"FZHei-B01" size:autoScaleW(25)];
    collectLabel.textColor=rgba(255,255,255,1);
    
    UILabel *collectAddressLabel=[UILabel new];
    [bottomView addSubview:collectAddressLabel];
    [collectAddressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(xianView);
        make.right.mas_equalTo(-182*_mainWidth);
        make.bottom.mas_equalTo(collectLabel.mas_centerY).mas_equalTo(-_mainHeight*5);
    }];
    collectAddressLabel.numberOfLines=0;
    collectAddressLabel.font=[UIFont fontWithName:@"PingFang SC" size:autoScaleW(35)];
    collectAddressLabel.text=@"杭州市·新天地工程中城建六局";
    collectAddressLabel.textColor=rgba(47,47,47,1);
    
    UILabel *collectNameLabel=[UILabel new];
    [bottomView addSubview:collectNameLabel];
    [collectNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(xianView);
        make.right.mas_equalTo(-182*_mainWidth);
        make.top.mas_equalTo(collectLabel.mas_centerY).mas_equalTo(_mainHeight*5);
    }];
    collectNameLabel.numberOfLines=0;
    collectNameLabel.font=[UIFont fontWithName:@"PingFang SC" size:autoScaleW(35)];
    collectNameLabel.text=@"金有才\t13605443326";
    collectNameLabel.textColor=rgba(102,102,102,1);
    
    UIButton *collectBtn=[UIButton new];
    [bottomView addSubview:collectBtn];
    [collectBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-40*_mainWidth);
        make.centerY.mas_equalTo(0);
        make.width.mas_equalTo(101*_mainWidth);
        make.height.mas_equalTo(38*_mainHeight);
    }];
    [collectBtn setTitle:@"地址簿" forState:0];
    [collectBtn  setTitleColor:rgba(157,157,157,1) forState:0];
    collectBtn.titleLabel.font=[UIFont fontWithName:@"PingFang SC" size:autoScaleW(26)];
    collectBtn.layer.masksToBounds=YES;
    collectBtn.layer.borderColor=rgba(157,157,157,1).CGColor;
    collectBtn.layer.borderWidth=1;
    collectBtn.layer.cornerRadius=38*_mainHeight/2;
    collectBtn.tag=2;
    [collectBtn addTarget:self action:@selector(selectPushToAddressBtn:) forControlEvents:UIControlEventTouchUpInside];
    
    UIImageView *imageView=[UIImageView new];
    [centerView addSubview:imageView];
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(0);
        make.centerX.mas_equalTo(collectLabel);
        make.height.mas_equalTo(_mainHeight*90);
        make.width.mas_equalTo(15*_mainWidth);
    }];
    imageView.image=[UIImage imageNamed:@"daoxiangjiantou"];
    
}
-(void)creatBottomView{
    
    self.backgroundColor=[UIColor clearColor];
    
    UIView *centerView=[UIView new];
    [self.contentView addSubview:centerView];
    [centerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(30*_mainWidth);
        make.right.mas_equalTo(-30*_mainWidth);
        make.top.mas_equalTo(10*_mainHeight);
        make.bottom.mas_equalTo(-10*_mainHeight);
    }];
    centerView.backgroundColor=[UIColor whiteColor];
    centerView.layer.cornerRadius=25*_mainWidth;
    
    UIView *topView=[UIView new];
    [centerView addSubview:topView];
    [topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.top.left.mas_equalTo(0);
        make.height.mas_equalTo(119*_mainHeight);
    }];
    topView.userInteractionEnabled=YES;
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(selectTimeTap)];
    [topView addGestureRecognizer:tapGesture];
    
    UIView *xianView=[UIView new];
    [topView addSubview:xianView];
    [xianView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(40*_mainWidth);
        make.right.mas_equalTo(-40*_mainWidth);
        make.height.mas_equalTo(_mainHeight);
        make.top.mas_equalTo(topView.mas_bottom);
    }];
    xianView.backgroundColor=rgba(232,232,232,1);
 
    UILabel *leftLabel=[UILabel new];
    [topView addSubview:leftLabel];
    [leftLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(40*_mainWidth);
        make.centerY.mas_equalTo(0);
    }];
    leftLabel.text=@"上门时间";
    leftLabel.textColor=rgba(44,46,52,1);
    leftLabel.font=[UIFont fontWithName:@"PingFang SC" size:autoScaleW(30)];
    
    
    UILabel *rightLabel=[UILabel new];
    [topView addSubview:rightLabel];
    [rightLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(0);
        make.right.mas_equalTo(-40*_mainWidth);
    }];
    NSString *typeStr=@"今天一小时内 ";
    NSMutableAttributedString *attri =  [[NSMutableAttributedString alloc] initWithString:typeStr];
    // 2.添加表情图片
    NSTextAttachment *attch = [[NSTextAttachment alloc] init];
    // 表情图片
    attch.image = [UIImage imageNamed:@"gengduo"];
        // 设置图片大小
    attch.bounds = CGRectMake(0, 0, 5.5, 12);
    // 创建带有图片的富文本
    NSAttributedString *string = [NSAttributedString attributedStringWithAttachment:attch];
    [attri insertAttributedString:string atIndex:typeStr.length];//插入某个位置
   
    rightLabel.attributedText=attri;
    rightLabel.textColor=rgba(44,46,52,1);
    rightLabel.font=[UIFont fontWithName:@"PingFang SC" size:autoScaleW(35)];
    rightLabel.textAlignment=NSTextAlignmentRight;
    
    UIView *topView2=[UIView new];
    [centerView addSubview:topView2];
    [topView2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.left.mas_equalTo(0);
        make.top.mas_equalTo(xianView.mas_bottom);
        make.height.mas_equalTo(122*_mainHeight);
    }];
    topView2.userInteractionEnabled=YES;
    UITapGestureRecognizer *tapGesture2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(selectShippingTap)];
    [topView2 addGestureRecognizer:tapGesture2];
    
    
    UIView *xianView2=[UIView new];
    [topView2 addSubview:xianView2];
    [xianView2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(40*_mainWidth);
        make.right.mas_equalTo(-40*_mainWidth);
        make.height.mas_equalTo(_mainHeight);
        make.top.mas_equalTo(topView2.mas_bottom);
    }];
    xianView2.backgroundColor=rgba(232,232,232,1);
 
    UILabel *leftLabel2=[UILabel new];
    [topView2 addSubview:leftLabel2];
    [leftLabel2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(40*_mainWidth);
        make.centerY.mas_equalTo(0);
    }];
    leftLabel2.text=@"运输方式";
    leftLabel2.textColor=rgba(44,46,52,1);
    leftLabel2.font=[UIFont fontWithName:@"PingFang SC" size:autoScaleW(30)];
    
    UILabel *rightLabel2=[UILabel new];
    [topView2 addSubview:rightLabel2];
    [rightLabel2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(0);
        make.right.mas_equalTo(-40*_mainWidth);
    }];
    NSString *typeStr2=@"大巴 ";
    NSMutableAttributedString *attri2 =  [[NSMutableAttributedString alloc] initWithString:typeStr2];
   
    NSAttributedString *string2 = [NSAttributedString attributedStringWithAttachment:attch];
    [attri2 insertAttributedString:string2 atIndex:typeStr2.length];//插入某个位置
    rightLabel2.attributedText=attri2;
    rightLabel2.textColor=rgba(44,46,52,1);
    rightLabel2.font=[UIFont fontWithName:@"PingFang SC" size:autoScaleW(35)];
    rightLabel2.textAlignment=NSTextAlignmentRight;
    
    
    UIView *topView3=[UIView new];
    [centerView addSubview:topView3];
    [topView3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.left.mas_equalTo(0);
        make.top.mas_equalTo(xianView2.mas_bottom);
        make.height.mas_equalTo(102*_mainHeight);
    }];
    
   
 
    UILabel *leftLabel3=[UILabel new];
    [topView3 addSubview:leftLabel3];
    [leftLabel3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(40*_mainWidth);
        make.centerY.mas_equalTo(0);
    }];
    leftLabel3.text=@"宠物信息";
    leftLabel3.textColor=rgba(44,46,52,1);
    leftLabel3.font=[UIFont fontWithName:@"PingFang SC" size:autoScaleW(30)];
    
    UIButton *myPetsBtn=[UIButton new];
    [topView3 addSubview:myPetsBtn];
    [myPetsBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(0);
        make.right.mas_equalTo(xianView);
        make.height.mas_equalTo(_mainHeight*38);
        make.width.mas_equalTo(_mainWidth*128);
    }];
    [myPetsBtn setTitle:@"我的宠物" forState:0];
    [myPetsBtn  setTitleColor:rgba(157,157,157,1) forState:0];
    myPetsBtn.titleLabel.font=[UIFont fontWithName:@"PingFang SC" size:autoScaleW(26)];
    myPetsBtn.layer.masksToBounds=YES;
    myPetsBtn.layer.borderColor=rgba(157,157,157,1).CGColor;
    myPetsBtn.layer.borderWidth=1;
    myPetsBtn.layer.cornerRadius=38*_mainHeight/2;
    [myPetsBtn addTarget:self action:@selector(selectPushToMyPetBtn) forControlEvents:UIControlEventTouchUpInside];
    
    UIView *bottomView=[UIView new];
    [centerView addSubview:bottomView];
    [bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(24*_mainWidth);
        make.right.mas_equalTo(-17*_mainWidth);
        make.top.mas_equalTo(345*_mainHeight);
        make.bottom.mas_equalTo(-31*_mainHeight);
    }];
    bottomView.backgroundColor=rgba(248,248,247,1);
    bottomView.layer.cornerRadius=25*_mainWidth/2;
    bottomView.layer.masksToBounds=YES;
    
    NSDictionary *dic=@{@"dog":@"狗",@"name":@"小花",@"type":@"大型",@"weight":@"6～8kg"};
    NSDictionary *dic2=@{@"dog":@"狗",@"name":@"小花花花",@"type":@"大型",@"weight":@"6～18kg"};
    NSArray *arr=@[dic,dic2];
    for (int i=0; i<arr.count; i++) {
        NSDictionary *typeDic=arr[i];
        NSString *dog=typeDic[@"dog"];
        NSString *name=typeDic[@"name"];
        NSString *type=typeDic[@"type"];
        NSString *weight=typeDic[@"weight"];
        
        UIView *backView=[UIView new];
        [bottomView addSubview:backView];
        [backView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(30*_mainWidth);
            make.top.mas_equalTo(24*_mainHeight+60*_mainHeight*i+10*_mainHeight*i);
            make.width.mas_equalTo(100);
            make.height.mas_equalTo(60*_mainHeight);
        }];
        backView.layer.masksToBounds=YES;
        backView.layer.cornerRadius=30*_mainHeight;
        backView.layer.borderWidth=1;
        backView.layer.borderColor=rgba(46,48,54,1).CGColor;
        
        UILabel *label=[UILabel new];
        [backView addSubview:label];
        [label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(30*_mainWidth);
            make.centerY.mas_equalTo(0);
        }];
        [label layoutIfNeeded];
        label.text=dog;
        label.font=[UIFont fontWithName:@"PingFang SC" size:autoScaleW(26)];
        label.textColor=rgba(44,46,52,1);
        
        UIView *dogXian=[UIView new];
        [backView addSubview:dogXian];
        [dogXian mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(label.mas_right).mas_equalTo(10*_mainWidth);
            make.centerY.mas_equalTo(0);
            make.width.mas_equalTo(1*_mainWidth);
            make.height.mas_equalTo(23*_mainHeight);
        }];
        dogXian.backgroundColor=rgba(151,151,151,1);
        
        UILabel *label2=[UILabel new];
        [backView addSubview:label2];
        [label2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(dogXian.mas_right).mas_equalTo(10*_mainWidth);
            make.centerY.mas_equalTo(0);

        }];
        [label2 layoutIfNeeded];
        label2.text=name;
        label2.font=[UIFont fontWithName:@"PingFang SC" size:autoScaleW(26)];
        label2.textColor=rgba(44,46,52,1);
        
        UIView *dogXian2=[UIView new];
        [backView addSubview:dogXian2];
        [dogXian2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(label2.mas_right).mas_equalTo(10*_mainWidth);
            make.centerY.mas_equalTo(0);
            make.width.mas_equalTo(1*_mainWidth);
            make.height.mas_equalTo(23*_mainHeight);
        }];
        dogXian2.backgroundColor=rgba(151,151,151,1);
        
        UILabel *label3=[UILabel new];
        [backView addSubview:label3];
        [label3 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(dogXian2.mas_right).mas_equalTo(10*_mainWidth);
            make.centerY.mas_equalTo(0);
        }];
        [label3 layoutIfNeeded];
        label3.text=type;
        label3.font=[UIFont fontWithName:@"PingFang SC" size:autoScaleW(26)];
        label3.textColor=rgba(44,46,52,1);

        UIView *dogXian3=[UIView new];
        [backView addSubview:dogXian3];
        [dogXian3 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(label3.mas_right).mas_equalTo(10*_mainWidth);
            make.centerY.mas_equalTo(0);
            make.width.mas_equalTo(1*_mainWidth);
            make.height.mas_equalTo(23*_mainHeight);
        }];
        dogXian3.backgroundColor=rgba(151,151,151,1);

        
        UILabel *label4=[UILabel new];
        [backView addSubview:label4];
        [label4 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(dogXian3.mas_right).mas_equalTo(10*_mainWidth);
            make.centerY.mas_equalTo(0);
        }];
        [label4 layoutIfNeeded];
        label4.text=weight;
        label4.font=[UIFont fontWithName:@"PingFang SC" size:autoScaleW(26)];
        label4.textColor=rgba(44,46,52,1);
        
        NSDictionary *attrs = @{NSFontAttributeName : [UIFont fontWithName:@"PingFang SC" size:autoScaleW(26)]};
        CGSize size=[label.text sizeWithAttributes:attrs];
        CGSize size2=[label2.text sizeWithAttributes:attrs];
        CGSize size3=[label3.text sizeWithAttributes:attrs];
        CGSize size4=[label4.text sizeWithAttributes:attrs];
        
        
        CGFloat width=size.width+size2.width+size3.width+size4.width+92*_mainWidth+63*_mainWidth;

        if (width>_mainW-84*2*_mainWidth) {
            width=_mainW-84*2*_mainWidth;
        }
        [backView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(width);
        }];
        
        UIButton *deleteBtn=[UIButton new];
        [backView addSubview:deleteBtn];
        [deleteBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(-15*_mainWidth);
            make.height.width.mas_equalTo(_mainWidth*33);
            make.centerY.mas_equalTo(0);
        }];
        [deleteBtn setImage:[UIImage imageNamed:@"shanchu"] forState:0];
        
    }
    
    UIButton *increaseBtn=[UIButton new];
    [bottomView addSubview:increaseBtn];
    [increaseBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(30*_mainWidth);
        make.width.height.mas_equalTo(76*_mainHeight);
        make.bottom.mas_equalTo(-29*_mainHeight);
    }];
    [increaseBtn setImage:[UIImage imageNamed:@"tianjia"] forState:0];
}

-(void)selectPushToMyPetBtn{
    if (self.delegate!=nil) {
        [self.delegate selectPushToMyPet];
    }
}

-(void)selectPushToAddressBtn:(UIButton *)btn{
    if (self.delegate!=nil) {
        [self.delegate selectPushToAddress:btn.tag];
    }
}
-(void)selectTimeTap{
    if (self.delegate!=nil) {
        [self.delegate selectTime];
    }
}
-(void)selectShippingTap{
    if (self.delegate!=nil) {
        [self.delegate selectShipping];
    }
}
@end
